package jmine.tec.script.persistent.dao;

import java.io.Serializable;

import jmine.tec.persist.naturalkey.InvalidNaturalKeyException;
import jmine.tec.script.persistent.domain.ScriptPurpose;

import org.hibernate.Criteria;
import org.hibernate.criterion.CriteriaSpecification;

import bancosys.tec.persist.dao.BeanNotFoundException;
import bancosys.tec.persist.dao.SystemEntityDAO;

/**
 * DAO da entidade ScriptPurpose
 * 
 * @author lundberg
 */
public class ScriptPurposeDAO extends SystemEntityDAO<ScriptPurpose, ScriptPurposeIdentifier> {

    /**
     * {@inheritDoc}
     */
    @Override
    public ScriptPurpose findByNaturalKey(Serializable naturalKey) throws BeanNotFoundException {
        Criteria criteria = this.createCriteria();
        try {
            this.getNaturalKeyHandler().addRestrictionEq(criteria, naturalKey);
        } catch (InvalidNaturalKeyException e) {
            throw new BeanNotFoundException(this.getPersistableClass());
        }
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        return this.executeSingleQuery(criteria);
    }
}
